package com.shqcjd.generalplatformprojectclient.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;

import com.shqcjd.generalplatformprojectclient.R;
import com.shqcjd.generalplatformprojectclient.ui.base.BaseActivity;
import com.shqcjd.generalplatformprojectclient.ui.base.BasePresenter;
import com.shqcjd.generalplatformprojectclient.util.PrefUtils;

public class LauncherActivity extends BaseActivity {
    private final int TIMER = 1000;
    private final int FRE = 3;
    private int current = 0;
    private Context context;
    private Handler handler = new Handler();
    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            current++;
            if(current>=FRE){
                handler.removeCallbacks(runnable);
                Intent it;
                if(PrefUtils.getInt(context, PrefUtils.USER_USER_ID, 0)==0){
                    it = new Intent(LauncherActivity.this, LoginActivity.class);
                }else{
                    it = new Intent(LauncherActivity.this, MainActivity.class);
                }
                startActivity(it);
                finish();
            }else{
                handler.postDelayed(runnable, TIMER);
            }
        }
    };

    @Override
    public void init() {
        super.init();
        context = this;
    }

    @Override
    public void initView() {
        super.initView();
        handler.postDelayed(runnable, TIMER);
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_launcher;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(handler!=null){
            handler.removeCallbacks(runnable);
        }
    }

}
